package com.plian.system.quartz;

import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.task.indicatorswarning.IndicatorsWarningTask;
import com.plian.system.task.zhibiao.ZhiBiaoTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QuartTask {
    @Autowired
    QuartzManager quartzManager;
    public  void task(
        String fun,
        String timingType,
        String timingMonth,
        String timingDay,
        String timingHour,
        String timmingMinutes
    ){
        String code_date = "";
        if ("1".equals(timingType)) {
            code_date = "0 " + timmingMinutes + " " + timingHour + " " + timingDay + " * ?";
        }else
        if ("2".equals(timingType)) {
            code_date = "0 " + timmingMinutes + " " + timingHour + " * * ?";
        }else
        if ("0".equals(timingType)) {
            code_date = "0 " + timmingMinutes + " " + timingHour + " " + timingDay + " " + timingMonth + " ?";
        }else {
            throw  new MyRuntimeException("参数错误");
        }
        if("0".equals(fun)){
            quartzManager.addJob("zhibiao", ZhiBiaoTask.class, code_date);
        }
        if("1".equals(fun)){
            quartzManager.addJob("indicatorsWarning", IndicatorsWarningTask.class, code_date);
        }
    }
    public void delTask(String fun) {
        if ("0".equals(fun)) {
            quartzManager.removeJob("zhibiao");
        }else
        if ("1".equals(fun)) {
            quartzManager.removeJob("indicatorsWarning");
        } else {
            throw new MyRuntimeException("参数错误");
        }
    }

}
